package com.auxgroup.smarthome.repo;


import com.auxgroup.smarthome.entity.SysMessageSendEntity;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;

/**
 * Created by fju on 2017/8/7.
 */
public interface SysMessageSendEntityRepo extends GenericDao<SysMessageSendEntity,String>{

    @Query(value = "update SysMessageSendEntity s set s.progress = :progress where s.userId = :userId and s.sysMessageId in (:ids)")
    @Modifying
    @Transactional
    int updateProgress(@Param("userId") String userId, @Param("progress") Integer progress,@Param("ids") Collection<String> ids);

    @Query(value = "update SysMessageSendEntity s set s.progress = 2 where s.userId = :userId")
    @Modifying
    @Transactional
    int updateProgressToDel(@Param("userId") String userId);

    SysMessageSendEntity findByUserIdAndSysMessageId(String userId,String messageId);
}
